package com.gitee.ywj1352.webFlux.load;

import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author wenjie.yang on 2019/7/16.
 */
public class ParallelLoader {

    public static void main(String[] args) {
        doload();
    }
    //rt = 3秒
    protected static void doload(){
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        ExecutorCompletionService completionService = new ExecutorCompletionService(executorService);
        completionService.submit(()->{
            Thread.sleep(1000);
            System.out.println("1000");
            return 1;
        });
        completionService.submit(()->{
            Thread.sleep(2000);
            System.out.println("2000");
            return 1;
        });
        //木桶效应
        completionService.submit(()->{
            Thread.sleep(3000);
            System.out.println("3000");
            return 1;
        });
        int count = 0;
        while(count<3){
            if (completionService.poll()!=null){
                count ++;
            }
        }
        executorService.shutdown();
    }


}
